package com.xhs.open.api.impl;

import com.xhs.common.error.XhsErrorException;
import com.xhs.miniapp.api.impl.XhsMaServiceImpl;
import com.xhs.miniapp.config.XhsMaConfig;
import com.xhs.open.api.XhsOpenComponentService;
import com.xhs.open.api.XhsOpenMaService;

/**
 * <pre>
 *     增加开放平台代小程序管理服务能力
 *     说明：这里让这个服务公开便于调用者模拟本地测试服务
 * </pre>
 */
public class XhsOpenMaServiceImpl extends XhsMaServiceImpl implements XhsOpenMaService {
  private static final String ACTION = "action";
  private static final String ACTION_GET = "get";
  private final XhsOpenComponentService wxOpenComponentService;
  private final XhsMaConfig wxMaConfig;
  private final String appId;

  public XhsOpenMaServiceImpl(XhsOpenComponentService wxOpenComponentService, String appId, XhsMaConfig wxMaConfig) {
    this.wxOpenComponentService = wxOpenComponentService;
    this.appId = appId;
    this.wxMaConfig = wxMaConfig;
    initHttp();
  }

  @Override
  public XhsMaConfig getWxMaConfig() {
    return wxMaConfig;
  }

  @Override
  public String getAccessToken(boolean forceRefresh) throws XhsErrorException {
    return wxOpenComponentService.getAuthorizerAccessToken(appId, forceRefresh);
  }
}
